package top.suven.base.core.mq.activemq;

import org.apache.activemq.command.ActiveMQQueue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.core.JmsMessagingTemplate;

import javax.jms.Queue;

/**
 * @ClassName:
 * @Description:
 * @Author lixiangling
 * @Date 2018/6/28 10:04
 * @Copyright: (c) 2018 gc by https://www.gc.com.cn/
 * @Version : 1.0.0
 * --------------------------------------------------------
 * modifyer    modifyTime                 comment
 * <p>
 * --------------------------------------------------------
 */
public class ActiveThreadMq implements Runnable {
    private JmsMessagingTemplate jmsMessagingTemplate;
    private String queueName;
    private Object message;
    private Logger logger = LoggerFactory.getLogger(ActiveThreadMq.class);


    public ActiveThreadMq(JmsMessagingTemplate jmsMessagingTemplate,String queueName,Object message){
        this.jmsMessagingTemplate = jmsMessagingTemplate;
        this.queueName = queueName;
        this.message = message;
    }


    @Override
    public void run() {
        try {
            Queue destination = new ActiveMQQueue(queueName);
            jmsMessagingTemplate.convertAndSend(destination, message);
        }catch (Exception e){
            logger.error(String.format("activeMq send message is error queueName=%s,msg=%s", queueName,String.valueOf(message)),e);
        }
    }
}
